<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">





        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/admin/Datacenter/UserRegList?action=ajax',
            method: 'post',
            parseData: function (res) { //res 即为原始返回的数据
                $('#countNum').html(res.count);
            },
            // 名称 分类 联系人 联系方式 应收应付 备注 状态

            cols: [[
                {field: 'address_all', title: '地区' },
                {field: 'num', title: '数量'},
            ]],
            limits: [10, 15, 20, 25, 30, 50, 100],
            limit: 10,
            page: true,
            skin: 'line,row',

        });


        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;

            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑 快递信息',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['80%', '80%'],
                    content: '/admin/express/Saveinfo?id='+obj.data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;

            }

            if (obj.event === 'delete') {

                layer.confirm('真的删除行么', function (index) {
                    console.log(obj)
                    $.ajax({
                        url: '/admin/express/DelInfo',
                        type: 'post',
                        dataType: 'json',
                        data: {
                            id: obj.data.id,
                        },
                        success: function(data) {
                            if (data.status) {
                                layer.msg('删除成功!', {icon: 1, time: 1000});
                                $(obj)[0].tr.remove()

                            }else{
                                layer.msg(data.msg, {
                                    icon: 2,
                                    time: 3000
                                });
                            }
                        },
                        error: function(re) {
                            console.log(re)
                            layer.open({
                                title: '删除失败',
                                content: '<span style="color:red">'+re.responseJSON.errorCode+':</span>'+re.responseJSON.msg
                            })
                        }
                    });


                    // $(obj)[0].tr.remove()
                });
            }
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {

            if (obj.event === 'add') {  // 监听添加操作
                let index = layer.open({
                    title: '添加物流',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['60%', '60%'],
                    content: '/admin/express/Saveinfo'
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }

        });

    });
</script>

</body>
</html>